/*      */ package com.newcrm.db;
/*      */ 
/*      */ import com.newcrm.bean.ExtInfo;
/*      */ import com.newcrm.exception.DBException;
/*      */ import com.newcrm.util.Util;
/*      */ import java.sql.Connection;
/*      */ import java.sql.SQLException;
/*      */ import java.util.ArrayList;
/*      */ import java.util.Date;
/*      */ import java.util.List;
/*      */ import java.util.Map;
/*      */ import org.apache.commons.dbutils.DbUtils;
/*      */ import org.apache.commons.dbutils.GenKeyQueryRunner;
/*      */ import org.apache.commons.dbutils.MyMapHandler;
/*      */ import org.apache.commons.dbutils.MyMapListHandler;
/*      */ import org.apache.commons.dbutils.QueryRunner;
/*      */ import org.apache.commons.dbutils.handlers.ArrayHandler;
/*      */ import org.apache.commons.dbutils.handlers.ScalarHandler;
/*      */ import org.apache.log4j.Logger;
/*      */ 
/*      */ public class DealManager
/*      */ {
/*   27 */   private static Logger logger = Logger.getLogger(DealManager.class.getName());
/*      */ 
/*      */   public int update(int dealId, int customerId, String customerName, int customerType, String name, String note, int categoryId, String responsibleUserId, float price, float commission, List<ExtInfo> extInfos, int companyId, String userId, String userName)
/*      */     throws DBException
/*      */   {
/*   54 */     if ((name == null) || (name.trim().length() == 0)) {
/*   55 */       return -1;
/*      */     }
/*      */ 
/*   58 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*   59 */     if (conn == null) {
/*   60 */       throw new DBException();
/*      */     }
/*   62 */     QueryRunner runner = new QueryRunner();
/*      */     try
/*      */     {
/*   67 */       int result = runner.update(conn, "UPDATE T_Deal_Info SET Name = ?, Note = ?, CategoryId = ?, ResponsibleUserId = ?, Price = ?, Commission = ?, CustomerId = ?, UpdateUserId = ?, UpdateDate = NOW() WHERE DealId = ?", new Object[] { name, note, 
/*   68 */         Integer.valueOf(categoryId), responsibleUserId, Float.valueOf(price), Float.valueOf(commission), 
/*   69 */         Integer.valueOf(customerId), userId, Integer.valueOf(dealId) });
/*      */ 
/*   73 */       runner.update(conn, "UPDATE T_Customer_Deal_Info SET CustomerId = ?, CustomerName = ?, CustomerType = ? WHERE DealId = ? AND PrimaryFlag = 1", new Object[] { Integer.valueOf(customerId), 
/*   74 */         customerName, Integer.valueOf(customerType), Integer.valueOf(dealId) });
/*      */ 
/*   77 */       if ((extInfos != null) && (extInfos.size() > 0)) {
/*   78 */         List addParams = new ArrayList();
/*   79 */         List updateParams = new ArrayList();
/*   80 */         List deleteParams = new ArrayList();
/*   81 */         for (ExtInfo extInfo : extInfos) {
/*   82 */           List info = new ArrayList();
/*   83 */           if (extInfo.id > 0) {
/*   84 */             if ((extInfo.info1 == null) || 
/*   85 */               (extInfo.info1.trim().length() == 0)) {
/*   86 */               info.add(Integer.valueOf(extInfo.id));
/*   87 */               deleteParams.add(info.toArray(new Object[0]));
/*      */             } else {
/*   89 */               info.add(extInfo.info1);
/*   90 */               info.add(extInfo.info2);
/*   91 */               info.add(extInfo.info3);
/*   92 */               info.add(extInfo.info4);
/*   93 */               info.add(Integer.valueOf(extInfo.id));
/*   94 */               updateParams.add(info.toArray(new Object[0]));
/*      */             }
/*      */           } else {
/*   97 */             info.add(Integer.valueOf(companyId));
/*   98 */             info.add(Integer.valueOf(dealId));
/*   99 */             info.add(Integer.valueOf(extInfo.type));
/*  100 */             info.add(extInfo.info1);
/*  101 */             info.add(extInfo.info2);
/*  102 */             info.add(extInfo.info3);
/*  103 */             info.add(extInfo.info4);
/*  104 */             addParams.add(info.toArray(new Object[0]));
/*      */           }
/*      */         }
/*      */ 
/*  108 */         if (updateParams.size() > 0) {
/*  109 */           runner.batch(conn, "UPDATE T_Deal_Ext_Info SET Info1 = ?, Info2 = ?, Info3 = ?, Info4 = ? WHERE DealExtId = ?", 
/*  110 */             (Object[][])updateParams.toArray(new Object[0][]));
/*      */         }
/*      */ 
/*  113 */         if (addParams.size() > 0) {
/*  114 */           runner.batch(conn, "INSERT INTO T_Deal_Ext_Info (CompanyId,DealId,Type,Info1,Info2,Info3,Info4,CreateDate) VALUES (?,?,?,?,?,?,?,NOW())", 
/*  115 */             (Object[][])addParams.toArray(new Object[0][]));
/*      */         }
/*      */ 
/*  118 */         if (deleteParams.size() > 0) {
/*  119 */           runner.batch(conn, "DELETE FROM T_Deal_Ext_Info WHERE DealExtId = ?", 
/*  120 */             (Object[][])deleteParams.toArray(new Object[0][]));
/*      */         }
/*      */       }
/*      */ 
/*  124 */       return result;
/*      */     } catch (SQLException e) {
/*  126 */       logger.warn("update deal failed", e);
/*  127 */       throw new DBException();
/*      */     } finally {
/*      */       try {
/*  130 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/*  132 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*      */   }
/*      */ 
/*      */   public int add(int customerId, String customerName, int customerType, int primaryFlag, String name, String note, int categoryId, String responsibleUserId, int visible, String permissionsId, float price, float commission, List<ExtInfo> extInfos, int companyId, String userId)
/*      */   {
/*  162 */     if ((name == null) || (name.trim().length() == 0)) {
/*  163 */       return 0;
/*      */     }
/*      */ 
/*  166 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  167 */     if (conn == null) {
/*  168 */       return 0;
/*      */     }
/*      */     try
/*      */     {
/*  172 */       GenKeyQueryRunner runner = new GenKeyQueryRunner(
/*  173 */         new ScalarHandler(), new String[] { "DealId" });
/*      */ 
/*  175 */       runner.update(conn, "INSERT INTO T_Deal_Info (Name,Note,CategoryId,ResponsibleUserId,DealVisible,PermissionsId,Price,Commission,CompanyId,DealStatus,CustomerId,CreateUserId,UpdateUserId,CreateDate,UpdateDate,DealStatusChangeDate) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,NOW(),NOW(),NOW())", new Object[] { name, note, Integer.valueOf(categoryId), 
/*  176 */         responsibleUserId, Integer.valueOf(visible), permissionsId, Float.valueOf(price), 
/*  177 */         Float.valueOf(commission), Integer.valueOf(companyId), Integer.valueOf(1), 
/*  178 */         Integer.valueOf(customerId), userId, userId });
/*      */ 
/*  180 */       int dealId = ((Long)runner.getGeneratedKeys()).intValue();
/*      */ 
/*  183 */       if ((extInfos != null) && (extInfos.size() > 0)) {
/*  184 */         List baseParams = new ArrayList();
/*  185 */         for (ExtInfo extInfo : extInfos)
/*  186 */           if ((extInfo.info1 != null) && 
/*  187 */             (extInfo.info1.trim().length() != 0))
/*      */           {
/*  190 */             List info = new ArrayList();
/*  191 */             info.add(Integer.valueOf(companyId));
/*  192 */             info.add(Integer.valueOf(dealId));
/*  193 */             info.add(Integer.valueOf(extInfo.type));
/*  194 */             info.add(extInfo.info1);
/*  195 */             info.add(extInfo.info2);
/*  196 */             info.add(extInfo.info3);
/*  197 */             info.add(extInfo.info4);
/*  198 */             baseParams.add(info.toArray(new Object[0]));
/*      */           }
/*  200 */         runner.batch(conn, "INSERT INTO T_Deal_Ext_Info (CompanyId,DealId,Type,Info1,Info2,Info3,Info4,CreateDate) VALUES (?,?,?,?,?,?,?,NOW())", 
/*  201 */           (Object[][])baseParams.toArray(new Object[0][]));
/*      */       }
/*      */ 
/*  205 */       runner.update(conn, "INSERT INTO T_Customer_Deal_Info (DealId,CustomerId,CustomerName,CustomerType,PrimaryFlag,CompanyId,CreateDate) VALUES (?,?,?,?,?,?,NOW())", new Object[] { Integer.valueOf(dealId), 
/*  206 */         Integer.valueOf(customerId), customerName, Integer.valueOf(customerType), Integer.valueOf(primaryFlag), 
/*  207 */         Integer.valueOf(companyId) });
/*      */ 
/*  213 */       runner.update(conn, "INSERT INTO T_Note_Info (NoteType,SubjectId,SubjectName,SubjectType,AttachFiles,NoteDate,NextContactDate,Remark,NoteVisible,PermissionsId,CompanyId,DealId,DealName,CreateUserId,UpdateUserId,CreateDate,UpdateDate) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW(),NOW())", new Object[] { Integer.valueOf(1), 
/*  214 */         Integer.valueOf(dealId), name, Integer.valueOf(2), "", new Date(), null, 
/*  215 */         "1", Integer.valueOf(1), "", 
/*  216 */         Integer.valueOf(companyId), Integer.valueOf(dealId), name, userId, userId });
/*  217 */       return dealId;
/*      */     } catch (SQLException e) {
/*  219 */       logger.warn("add deal failed", e);
/*      */     } finally {
/*      */       try {
/*  222 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/*  224 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*  227 */     return 0;
/*      */   }
/*      */ 
/*      */   public Map<String, Object> getDealInfo(int dealId)
/*      */   {
/*  238 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  239 */     if (conn == null) {
/*  240 */       return null;
/*      */     }
/*  242 */     QueryRunner runner = new QueryRunner();
/*      */     try {
/*  244 */       return (Map)runner.query(conn, "SELECT A.DealId, A.Name, A.Note, A.CategoryId, A.ResponsibleUserId, A.Price, A.Commission, A.DealStatus, A.CustomerId, A.LastContactDate, A.CreateDate, A.UpdateDate, A.DealStatusChangeDate, A.CreateUserId, A.UpdateUserId, B.Name AS CustomerName, B.Type AS CustomerType FROM T_Deal_Info AS A LEFT JOIN T_Customer_Info AS B ON A.CustomerId = B.CustomerId WHERE B.DeleteFlag = 0 AND A.DealId = ? ", 
/*  245 */         new MyMapHandler(), new Object[] { Integer.valueOf(dealId) });
/*      */     } catch (SQLException e) {
/*  247 */       logger.warn("get deal info failed", e);
/*      */     } finally {
/*      */       try {
/*  250 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/*  252 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*  255 */     return null;
/*      */   }
/*      */ 
/*      */   public List<ExtInfo> getDealExtInfo(int dealId)
/*      */   {
/*  265 */     List extInfos = new ArrayList();
/*  266 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  267 */     if (conn == null) {
/*  268 */       return extInfos;
/*      */     }
/*      */ 
/*  271 */     QueryRunner runner = new QueryRunner();
/*      */     try {
/*  273 */       List result = (List)runner.query(conn, 
/*  274 */         "SELECT * FROM T_Deal_Ext_Info WHERE DealId = ? ORDER BY Type ASC", new MyMapListHandler(), new Object[] { Integer.valueOf(dealId) });
/*  275 */       if (result != null)
/*  276 */         for (Object itemO : result) {
                Map item = (Map)itemO;
/*  277 */           ExtInfo info = new ExtInfo();
/*  278 */           info.id = Util.str2Int(item.get("DealExtId"));
/*  279 */           info.type = Util.str2Int(item.get("Type"));
/*  280 */           info.info1 = ((String)item.get("Info1"));
/*  281 */           info.info2 = ((String)item.get("Info2"));
/*  282 */           info.info3 = ((String)item.get("Info3"));
/*  283 */           info.info4 = ((String)item.get("Info4"));
/*  284 */           extInfos.add(info);
/*      */         }
/*      */     }
/*      */     catch (SQLException e)
/*      */     {
/*  289 */       logger.warn("get deal extInfo failed", e);
/*      */       try
/*      */       {
/*  292 */         DbUtils.close(conn);
/*      */       } catch (SQLException se) {
/*  294 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*      */     finally
/*      */     {
/*      */       try
/*      */       {
/*  292 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/*  294 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*  297 */     return extInfos;
/*      */   }
/*      */ 
/*      */   public List<Map<String, Object>> getDealCustomerInfo(int dealId)
/*      */     throws SQLException
/*      */   {
/*  309 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  310 */     if (conn == null) {
/*  311 */       return null;
/*      */     }
/*  313 */     QueryRunner runner = new QueryRunner();
/*      */     try {
/*  315 */       return (List)runner.query(conn, "SELECT A.DealId,A.CustomerId,B.Name,B.Type,A.PrimaryFlag, C.Name as ParentName, B.ParentCustomerId FROM T_Customer_Deal_Info AS A INNER JOIN T_Customer_Info AS B ON A.CustomerId = B.CustomerId LEFT JOIN T_Customer_Info AS C ON B.ParentCustomerId = C.CustomerId WHERE B.DeleteFlag = 0 AND (C.DeleteFlag is NULL OR C.DeleteFlag = 0) AND A.DealId = ? ORDER BY A.PrimaryFlag DESC", 
/*  316 */         new MyMapListHandler(), new Object[] { Integer.valueOf(dealId) });
/*      */     } finally {
/*      */       try {
/*  319 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/*  321 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*      */   }
/*      */ 
/*      */   public Map<String, Object> getNoteInfo(int dealId)
/*      */     throws DBException
/*      */   {
/*  334 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  335 */     if (conn == null) {
/*  336 */       return null;
/*      */     }
/*  338 */     QueryRunner runner = new QueryRunner();
/*      */     try {
/*  340 */       List result = (List)runner.query(conn, 
/*  341 */         "SELECT A.DealId, A.Name, A.Note, A.PermissionsId, A.CreateUserId, A.DealVisible, A.CustomerId, A.Mandatory, B.Name AS CustomerName FROM T_Deal_Info AS A LEFT JOIN T_Customer_Info AS B ON A.CustomerId = B.CustomerId WHERE B.DeleteFlag = 0 AND A.DealId = ? ", new MyMapListHandler(), new Object[] { Integer.valueOf(dealId) });
/*  342 */       if ((result != null) && (result.size() == 1)) {
/*  343 */         return (Map)result.get(0);
/*      */       }
/*  345 */       return null;
/*      */     } catch (SQLException e) {
/*  347 */       throw new DBException();
/*      */     } finally {
/*      */       try {
/*  350 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/*  352 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*      */   }
/*      */ 
/*      */   public int updateDealNote(int dealId, String note, String userId)
/*      */     throws DBException, SQLException
/*      */   {
/*  369 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  370 */     if (conn == null) {
/*  371 */       throw new DBException();
/*      */     }
/*  373 */     QueryRunner runner = new QueryRunner();
/*      */     try {
/*  375 */       return runner.update(conn, "UPDATE T_Deal_Info SET Note = ?, UpdateUserId = ?, UpdateDate = NOW() WHERE DealId = ?", new Object[] { note, 
/*  376 */         userId, Integer.valueOf(dealId) });
/*      */     } finally {
/*      */       try {
/*  379 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/*  381 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*      */   }
/*      */ 
/*      */   public int updateDealStatus(int dealId, int dealStatus, String dealName, String userId, int companyId)
/*      */     throws DBException, SQLException
/*      */   {
/*  400 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  401 */     if (conn == null) {
/*  402 */       throw new DBException();
/*      */     }
/*  404 */     QueryRunner runner = new QueryRunner();
/*      */     try
/*      */     {
/*  407 */       int result = runner.update(conn, "UPDATE T_Deal_Info SET DealStatus = ?, UpdateUserId = ?, UpdateDate = NOW(),DealStatusChangeDate = NOW() WHERE DealId = ?", new Object[] { 
/*  408 */         Integer.valueOf(dealStatus), userId, Integer.valueOf(dealId) });
/*  409 */       if (result == 1) {
/*  410 */         runner.update(conn, "INSERT INTO T_Note_Info (NoteType,SubjectId,SubjectName,SubjectType,AttachFiles,NoteDate,NextContactDate,Remark,NoteVisible,PermissionsId,CompanyId,DealId,DealName,CreateUserId,UpdateUserId,CreateDate,UpdateDate) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW(),NOW())", new Object[] { Integer.valueOf(1), 
/*  411 */           Integer.valueOf(dealId), null, Integer.valueOf(2), null, new Date(), null, 
/*  412 */           String.valueOf(dealStatus), Integer.valueOf(1), 
/*  413 */           null, Integer.valueOf(companyId), Integer.valueOf(dealId), dealName, userId, userId });
/*      */       }
/*  415 */       return result;
/*      */     } finally {
/*      */       try {
/*  418 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/*  420 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*      */   }
/*      */ 
/*      */   public int addDealCustomer(int dealId, int customerId, String customerName, int customerType, int primaryFlag, int companyId)
/*      */     throws DBException, SQLException
/*      */   {
/*  441 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  442 */     if (conn == null) {
/*  443 */       throw new DBException();
/*      */     }
/*  445 */     QueryRunner runner = new QueryRunner();
/*      */     try {
/*  447 */       return runner.update(conn, "INSERT INTO T_Customer_Deal_Info (DealId,CustomerId,CustomerName,CustomerType,PrimaryFlag,CompanyId,CreateDate) VALUES (?,?,?,?,?,?,NOW())", new Object[] { Integer.valueOf(dealId), 
/*  448 */         Integer.valueOf(customerId), customerName, Integer.valueOf(customerType), Integer.valueOf(primaryFlag), 
/*  449 */         Integer.valueOf(companyId) });
/*      */     } finally {
/*      */       try {
/*  452 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/*  454 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*      */   }
/*      */ 
/*      */   public int deleteDealCustomer(int dealId, int customerId)
/*      */     throws DBException, SQLException
/*      */   {
/*  470 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  471 */     if (conn == null) {
/*  472 */       throw new DBException();
/*      */     }
/*  474 */     QueryRunner runner = new QueryRunner();
/*      */     try {
/*  476 */       return runner.update(conn, "DELETE FROM T_Customer_Deal_Info WHERE DealId = ? AND CustomerId = ? ", new Object[] { Integer.valueOf(dealId), 
/*  477 */         Integer.valueOf(customerId) });
/*      */     } finally {
/*      */       try {
/*  480 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/*  482 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*      */   }
/*      */ 
/*      */   public String getName(int id)
/*      */     throws DBException
/*      */   {
/*  496 */     if (id <= 0) {
/*  497 */       return null;
/*      */     }
/*      */ 
/*  500 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  501 */     if (conn == null) {
/*  502 */       throw new DBException();
/*      */     }
/*      */ 
/*  505 */     QueryRunner runner = new QueryRunner();
/*      */     try
/*      */     {
/*  508 */       Object[] result = (Object[])runner.query(conn, "SELECT Name FROM T_Deal_Info WHERE DealId = ?", 
/*  509 */         new ArrayHandler(), new Object[] { Integer.valueOf(id) });
/*  510 */       if ((result == null) || (result.length == 0)) {
/*  511 */         return null;
/*      */       }
/*  513 */       return result[0].toString();
/*      */     } catch (SQLException e) {
/*  515 */       logger.warn("get deal failed", e);
/*      */     } finally {
/*      */       try {
/*  518 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/*  520 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*  523 */     return null;
/*      */   }
/*      */ 
/*      */   public int delete(int dealId)
/*      */     throws DBException, SQLException
/*      */   {
/*  535 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  536 */     if (conn == null) {
/*  537 */       throw new DBException();
/*      */     }
/*  539 */     QueryRunner runner = new QueryRunner();
/*      */     try
/*      */     {
/*  542 */       int result = runner.update(conn, "DELETE FROM T_Deal_Info WHERE DealId = ?", Integer.valueOf(dealId));
/*  543 */       runner.update(conn, "DELETE FROM T_Customer_Deal_Info WHERE DealId = ?", Integer.valueOf(dealId));
/*  544 */       runner.update(conn, "DELETE FROM T_Note_Info WHERE DealId = ?", Integer.valueOf(dealId));
/*  545 */       runner.update(conn, "DELETE FROM T_Task_Info WHERE ReferenceId = ? AND ReferenceType = 3", Integer.valueOf(dealId));
/*      */ 
/*  547 */       return result;
/*      */     } finally {
/*      */       try {
/*  550 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/*  552 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*      */   }
/*      */ 
/*      */   private StringBuffer getCommonSQL(List<Object> params, boolean isAdmin, int dealStatus, int categoryId, String responsibleUserId, String groupIds, String createDate, String wonDate, List<String[]> filters, String currentUserId, int companyId)
/*      */   {
/*  579 */     StringBuffer sql = new StringBuffer();
/*      */ 
/*  594 */     if (dealStatus > 0) {
/*  595 */       sql.append(" AND A.DealStatus = ? ");
/*  596 */       params.add(Integer.valueOf(dealStatus));
/*      */     }
/*      */ 
/*  599 */     if (categoryId > 0) {
/*  600 */       sql.append(" AND A.CategoryId = ? ");
/*  601 */       params.add(Integer.valueOf(categoryId));
/*      */     }
/*      */ 
/*  605 */     if ((responsibleUserId != null) && (responsibleUserId.length() > 0)) {
/*  606 */       sql.append(" AND A.ResponsibleUserId = ? ");
/*  607 */       params.add(responsibleUserId);
/*      */     }
/*  609 */     else if ((groupIds != null) && (groupIds.trim().length() > 0)) {
/*  610 */       if (!groupIds.contains(",")) {
/*  611 */         sql.append(" AND A.ResponsibleUserId IN (SELECT UserId FROM T_User_Info WHERE CompanyId = ? AND GroupId = ?) AND B.Visible = ?  ");
/*  612 */         params.add(Integer.valueOf(companyId));
/*  613 */         params.add(Integer.valueOf(Util.str2Int(groupIds)));
/*  614 */         params.add(Integer.valueOf(4));
/*      */       }
/*      */       else {
/*  617 */         sql.append(" AND A.ResponsibleUserId IN (SELECT UserId FROM T_User_Info WHERE CompanyId = ? AND GroupId IN (" + 
/*  618 */           groupIds + ")) AND B.Visible = ?  ");
/*  619 */         params.add(Integer.valueOf(companyId));
/*  620 */         params.add(Integer.valueOf(4));
/*      */       }
/*      */ 
/*      */     }
/*      */ 
/*  626 */     if ((createDate != null) && (createDate.trim().length() > 0)) {
/*  627 */       String[] arr = createDate.split("~");
/*  628 */       int len = arr.length;
/*  629 */       if (len > 1) {
/*  630 */         Date startDate = Util.str2Date(arr[0]);
/*  631 */         Date endDate = null;
/*  632 */         if (len > 1) {
/*  633 */           endDate = Util.str2Date(arr[1]);
/*      */         }
/*  635 */         if (startDate != null) {
/*  636 */           sql.append(" AND DATEDIFF(A.CreateDate, ?) >= 0 ");
/*  637 */           params.add(startDate);
/*      */         }
/*  639 */         if (endDate != null) {
/*  640 */           sql.append(" AND DATEDIFF(A.CreateDate, ?) <= 0 ");
/*  641 */           params.add(endDate);
/*      */         }
/*      */       }
/*      */ 
/*      */     }
/*      */ 
/*  647 */     if ((wonDate != null) && (wonDate.trim().length() > 0)) {
/*  648 */       String[] arr = wonDate.split("~");
/*  649 */       int len = arr.length;
/*  650 */       if (len > 1) {
/*  651 */         Date wonStartDate = Util.str2Date(arr[0]);
/*  652 */         Date wonEndDate = null;
/*  653 */         if (len > 1) {
/*  654 */           wonEndDate = Util.str2Date(arr[1]);
/*      */         }
/*      */ 
/*  658 */         if ((wonStartDate != null) || (wonEndDate != null)) {
/*  659 */           sql.append(" AND A.DealStatus = ? ");
/*  660 */           params.add(Integer.valueOf(2));
/*      */         }
/*  662 */         if (wonStartDate != null) {
/*  663 */           sql.append(" AND DATEDIFF(A.DealStatusChangeDate, ?) >= 0 ");
/*  664 */           params.add(wonStartDate);
/*      */         }
/*  666 */         if (wonEndDate != null) {
/*  667 */           sql.append(" AND DATEDIFF(A.DealStatusChangeDate, ?) <= 0 ");
/*  668 */           params.add(wonEndDate);
/*      */         }
/*      */       }
/*      */     }
/*      */ 
/*  673 */     sql.append(getFilterSQL(filters, params, companyId));
/*  674 */     return sql;
/*      */   }
/*      */ 
/*      */   private StringBuffer getFilterSQL(List<String[]> filters, List<Object> params, int companyId)
/*      */   {
/*  687 */     StringBuffer sql = new StringBuffer("");
/*  688 */     for (String[] filter : filters) {
/*  689 */       String name = filter[0];
/*  690 */       int valueType = Util.str2Int(filter[1]);
/*  691 */       String value = filter[2];
/*      */ 
/*  693 */       if ((name != "") && (value != ""))
/*      */       {
/*  697 */         if ("name".equals(name)) {
/*  698 */           sql.append(" AND A.Name like ?");
/*  699 */           params.add("%" + value + "%");
/*      */         }
/*  704 */         else if (name.contains("field")) {
/*  705 */           int type = 
/*  706 */             Util.str2Int(name.substring("field".length()));
/*  707 */           if (type >= 99)
/*      */           {
/*  711 */             if (valueType == 1) {
/*  712 */               if (value.indexOf("~") >= 0)
/*      */               {
/*  716 */                 String[] arr = value.split("~");
/*  717 */                 String start = arr[0].trim();
/*  718 */                 String end = null;
/*  719 */                 if (arr.length == 2) {
/*  720 */                   end = arr[1].trim();
/*      */                 }
/*      */ 
/*  724 */                 if ((Util.isNumeric(start)) || (Util.isNumeric(end)))
/*      */                 {
/*  727 */                   sql
/*  729 */                     .append(" AND A.DealId IN (SELECT DealId FROM T_Deal_Ext_Info WHERE CompanyId = ? AND Type = ? ");
/*  730 */                   params.add(Integer.valueOf(companyId));
/*  731 */                   params.add(Integer.valueOf(type));
/*  732 */                   if ((start != null) && (start.length() > 0)) {
/*  733 */                     sql.append(" AND Info1 >= " + start);
/*      */                   }
/*      */ 
/*  736 */                   if ((end != null) && (end.length() > 0)) {
/*  737 */                     sql.append(" AND Info1 <= " + end);
/*      */                   }
/*  739 */                   sql.append(")"); } 
/*      */               } } else if (valueType == 2) {
/*  741 */               if (value.indexOf("~") >= 0)
/*      */               {
/*  745 */                 String[] arr = value.split("~");
/*  746 */                 String start = arr[0].trim();
/*  747 */                 String end = null;
/*  748 */                 if (arr.length == 2) {
/*  749 */                   end = arr[1].trim();
/*      */                 }
/*  751 */                 sql
/*  753 */                   .append(" AND A.DealId IN (SELECT DealId FROM T_Deal_Ext_Info WHERE CompanyId = ? AND Type = ? ");
/*  754 */                 params.add(Integer.valueOf(companyId));
/*  755 */                 params.add(Integer.valueOf(type));
/*  756 */                 if ((start != null) && (start.length() > 0)) {
/*  757 */                   sql.append(" AND Info1 >= ? ");
/*  758 */                   params.add(start);
/*      */                 }
/*      */ 
/*  761 */                 if ((end != null) && (end.length() > 0)) {
/*  762 */                   sql.append(" AND Info1 <= ? ");
/*  763 */                   params.add(end);
/*      */                 }
/*  765 */                 sql.append(")");
/*      */               } } else if (valueType == 3) {
/*  767 */               sql
/*  769 */                 .append(" AND A.DealId IN (SELECT DealId FROM T_Deal_Ext_Info WHERE CompanyId = ? AND Type = ? AND Info1 = ?)");
/*  770 */               params.add(Integer.valueOf(companyId));
/*  771 */               params.add(Integer.valueOf(type));
/*  772 */               params.add(value);
/*      */             }
/*      */             else {
/*  775 */               sql
/*  777 */                 .append(" AND A.DealId IN (SELECT DealId FROM T_Deal_Ext_Info WHERE CompanyId = ? AND Type = ? AND Info1 like ?)");
/*  778 */               params.add(Integer.valueOf(companyId));
/*  779 */               params.add(Integer.valueOf(type));
/*  780 */               params.add("%" + value + "%");
/*      */             }
/*      */           }
/*      */         }
/*      */       }
/*      */     }
/*      */ 
/*  787 */     return sql;
/*      */   }
/*      */ 
/*      */   public List<Map<String, Object>> listAll(boolean isAdmin, int dealStatus, int categoryId, String responsibleUserId, String groupIds, String createDate, String wonDate, List<String[]> filters, String currentUserId, int offset, int pageSize, int companyId)
/*      */     throws DBException, SQLException
/*      */   {
/*  815 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  816 */     if (conn == null) {
/*  817 */       return null;
/*      */     }
/*  819 */     QueryRunner runner = new QueryRunner();
/*  820 */     StringBuffer sql = new StringBuffer();
/*      */ 
/*  822 */     if (pageSize == 0)
/*      */     {
/*  824 */       sql.append("SELECT A.DealId, A.Name, C.Name AS ParentName, A.Price, A.Commission, A.DealStatus, A.Note, A.ResponsibleUserId, A.CreateUserId, A.CategoryId, A.CreateDate, A.DealStatusChangeDate, B.CustomerId, B.Name AS CustomerName FROM T_Deal_Info AS A INNER JOIN T_Customer_Info AS B ON A.CustomerId = B.CustomerId LEFT JOIN T_Customer_Info AS C ON B.ParentCustomerId = C.CustomerId WHERE B.DeleteFlag = 0 AND A.CompanyId = ? ");
/*      */     }
/*  826 */     else sql.append("SELECT A.DealId, A.Name, A.Price, A.Commission, A.DealStatus, A.Note, A.ResponsibleUserId, A.CreateUserId, A.CustomerId, A.CategoryId, A.CreateDate, A.LastContactDate, B.Name AS CustomerName, B.Type AS CustomerType FROM T_Deal_Info AS A INNER JOIN T_Customer_Info AS B ON A.CustomerId = B.CustomerId WHERE B.DeleteFlag = 0 AND A.CompanyId = ? ");
/*      */ 
/*  828 */     List params = new ArrayList();
/*  829 */     params.add(Integer.valueOf(companyId));
/*      */ 
/*  831 */     sql.append(getCommonSQL(params, isAdmin, dealStatus, categoryId, 
/*  832 */       responsibleUserId, groupIds, createDate, wonDate, filters, 
/*  833 */       currentUserId, companyId));
/*      */ 
/*  835 */     sql.append(" ORDER BY A.DealStatus ASC, A.LastContactDate DESC, A.CreateDate DESC ");
/*  836 */     if (pageSize > 0)
/*  837 */       sql.append(" LIMIT ").append(offset).append(", ").append(pageSize);
/*      */     try
/*      */     {
/*  840 */       return (List)runner.query(conn, sql.toString(), new MyMapListHandler(), 
/*  841 */         params.toArray());
/*      */     } finally {
/*      */       try {
/*  844 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/*  846 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*      */   }
/*      */ 
/*      */   public List<Map<String, Object>> listWonDealsTotalInfo(boolean isAdmin, int dealStatus, int categoryId, String responsibleUserId, String groupIds, String createDate, String wonDate, List<String[]> filters, String currentUserId, int companyId)
/*      */     throws DBException, SQLException
/*      */   {
/*  875 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  876 */     if (conn == null) {
/*  877 */       return null;
/*      */     }
/*  879 */     QueryRunner runner = new QueryRunner();
/*  880 */     StringBuffer sql = new StringBuffer("SELECT COUNT(*) AS totalWonNum, sum(A.Price) AS totalMoney, sum(A.Commission) AS totalCommission FROM T_Deal_Info AS A INNER JOIN T_Customer_Info AS B ON A.CustomerId = B.CustomerId WHERE B.DeleteFlag = 0 AND A.CompanyId = ? ");
/*  881 */     List params = new ArrayList();
/*  882 */     params.add(Integer.valueOf(companyId));
/*  883 */     sql.append(getCommonSQL(params, isAdmin, dealStatus, categoryId, 
/*  884 */       responsibleUserId, groupIds, createDate, wonDate, filters, 
/*  885 */       currentUserId, companyId));
/*  886 */     sql.append(" AND A.DealStatus = ? ");
/*  887 */     params.add(Integer.valueOf(2));
/*      */     try {
/*  889 */       return (List)runner.query(conn, sql.toString(), new MyMapListHandler(), 
/*  890 */         params.toArray());
/*      */     } finally {
/*      */       try {
/*  893 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/*  895 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*      */   }
/*      */ 
/*      */   public int listAllCount(boolean isAdmin, int dealStatus, int categoryId, String responsibleUserId, String groupIds, String createDate, String wonDate, List<String[]> filters, String currentUserId, int companyId)
/*      */     throws DBException, SQLException
/*      */   {
/*  922 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  923 */     if (conn == null) {
/*  924 */       return 0;
/*      */     }
/*  926 */     QueryRunner runner = new QueryRunner();
/*  927 */     StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM T_Deal_Info AS A INNER JOIN T_Customer_Info AS B ON A.CustomerId = B.CustomerId WHERE B.DeleteFlag = 0 AND A.CompanyId = ? ");
/*  928 */     List params = new ArrayList();
/*  929 */     params.add(Integer.valueOf(companyId));
/*  930 */     sql.append(getCommonSQL(params, isAdmin, dealStatus, categoryId, 
/*  931 */       responsibleUserId, groupIds, createDate, wonDate, filters, 
/*  932 */       currentUserId, companyId));
/*      */     try
/*      */     {
/*  935 */       Object obj = runner.query(conn, sql.toString(), 
/*  936 */         new ScalarHandler(1), params.toArray());
/*  937 */       if (!(obj instanceof Long)) {
/*  938 */         return 0;
/*      */       }
/*  940 */       return ((Long)obj).intValue();
/*      */     } finally {
/*      */       try {
/*  943 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/*  945 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*      */   }
/*      */ 
/*      */   public List<Map<String, Object>> listCustomerDeals(String customerIds)
/*      */     throws DBException
/*      */   {
/*  959 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  960 */     if (conn == null) {
/*  961 */       return null;
/*      */     }
/*  963 */     QueryRunner runner = new QueryRunner();
/*      */     try {
/*  965 */       StringBuffer sql = new StringBuffer(
/*  966 */         "SELECT A.DealId, A.Name, A.Price, A.DealStatus, A.Note, A.ResponsibleUserId, A.CreateUserId, A.CategoryId, A.CustomerId, B.Name AS CustomerName, B.Type AS CustomerType FROM T_Deal_Info AS A INNER JOIN T_Customer_Info AS B ON A.CustomerId = B.CustomerId WHERE B.DeleteFlag = 0 AND A.CustomerId IN (");
/*  967 */       sql.append(customerIds).append(
/*  968 */         ") ORDER BY A.DealStatus ASC, A.LastContactDate DESC ");
/*  969 */       return (List)runner.query(conn, sql.toString(), new MyMapListHandler());
/*      */     } catch (SQLException e) {
/*  971 */       throw new DBException();
/*      */     } finally {
/*      */       try {
/*  974 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/*  976 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*      */   }
/*      */ 
/*      */   public int getPendingDealNumByGroupIds(int companyId, String groupIds)
/*      */   {
/*  988 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  989 */     if (conn == null) {
/*  990 */       return 0;
/*      */     }
/*      */ 
/*  993 */     StringBuffer sql = new StringBuffer();
/*  994 */     sql.append("SELECT COUNT(*) FROM T_Deal_Info AS A INNER JOIN T_Customer_Deal_Info AS B ON A.DealId = B.DealId WHERE A.DealStatus = ? AND A.CompanyId = ? ");
/*      */ 
/*  996 */     List params = new ArrayList();
/*  997 */     params.add(Integer.valueOf(1));
/*  998 */     params.add(Integer.valueOf(companyId));
/*      */ 
/* 1000 */     if ((groupIds != null) && (groupIds.trim().length() > 0)) {
/* 1001 */       sql.append(" AND A.ResponsibleUserId IN (SELECT UserId FROM T_User_Info WHERE CompanyId = ? AND GroupId IN (" + 
/* 1002 */         groupIds + ")) ");
/* 1003 */       params.add(Integer.valueOf(companyId));
/*      */     }
/*      */ 
/* 1006 */     QueryRunner runner = new QueryRunner();
/*      */     try {
/* 1008 */       Object obj = runner.query(conn, sql.toString(), 
/* 1009 */         new ScalarHandler(1), params.toArray());
/* 1010 */       if (!(obj instanceof Long)) {
/* 1011 */         return 0;
/*      */       }
/* 1013 */       return ((Long)obj).intValue();
/*      */     } catch (SQLException e) {
/* 1015 */       logger.warn("get count failed", e);
/*      */     } finally {
/*      */       try {
/* 1018 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/* 1020 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/* 1023 */     return 0;
/*      */   }
/*      */ 
/*      */   public int getPendingDealNumByUserId(int companyId, String userId)
/*      */   {
/* 1033 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 1034 */     if (conn == null) {
/* 1035 */       return 0;
/*      */     }
/*      */ 
/* 1038 */     StringBuffer sql = new StringBuffer();
/* 1039 */     sql.append("SELECT COUNT(*) FROM T_Deal_Info AS A INNER JOIN T_Customer_Deal_Info AS B ON A.DealId = B.DealId WHERE A.DealStatus = ? AND A.CompanyId = ? ");
/*      */ 
/* 1041 */     List params = new ArrayList();
/* 1042 */     params.add(Integer.valueOf(1));
/* 1043 */     params.add(Integer.valueOf(companyId));
/*      */ 
/* 1045 */     if ((userId != null) && (userId.trim().length() > 0)) {
/* 1046 */       sql.append(" AND A.ResponsibleUserId = ? ");
/* 1047 */       params.add(userId);
/*      */     }
/*      */ 
/* 1050 */     QueryRunner runner = new QueryRunner();
/*      */     try {
/* 1052 */       Object obj = runner.query(conn, sql.toString(), 
/* 1053 */         new ScalarHandler(1), params.toArray());
/* 1054 */       if (!(obj instanceof Long)) {
/* 1055 */         return 0;
/*      */       }
/* 1057 */       return ((Long)obj).intValue();
/*      */     } catch (SQLException e) {
/* 1059 */       logger.warn("get count failed", e);
/*      */     } finally {
/*      */       try {
/* 1062 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/* 1064 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/* 1067 */     return 0;
/*      */   }
/*      */ 
/*      */   public List<Map<String, Object>> getDealsTotalNumInfo(int companyId, String groupIds, int dealStatus)
/*      */     throws DBException
/*      */   {
/* 1081 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 1082 */     if (conn == null) {
/* 1083 */       return null;
/*      */     }
/* 1085 */     StringBuffer sql = new StringBuffer(
/* 1086 */       "SELECT COUNT(*) AS totalNum, ResponsibleUserId FROM T_Deal_Info WHERE CompanyId = ? ");
/* 1087 */     List params = new ArrayList();
/* 1088 */     params.add(Integer.valueOf(companyId));
/*      */ 
/* 1091 */     if (dealStatus > 0) {
/* 1092 */       sql.append(" AND DealStatus = ?");
/* 1093 */       params.add(Integer.valueOf(dealStatus));
/*      */     }
/*      */ 
/* 1096 */     if ((groupIds != null) && (groupIds.trim().length() > 0)) {
/* 1097 */       if (!groupIds.contains(",")) {
/* 1098 */         sql.append(" AND ResponsibleUserId IN (SELECT UserId FROM T_User_Info WHERE CompanyId = ? AND GroupId = ?)");
/* 1099 */         params.add(Integer.valueOf(companyId));
/* 1100 */         params.add(Integer.valueOf(Util.str2Int(groupIds)));
/*      */       } else {
/* 1102 */         sql.append(" AND ResponsibleUserId IN (SELECT UserId FROM T_User_Info WHERE CompanyId = ? AND GroupId IN (" + 
/* 1103 */           groupIds + "))");
/* 1104 */         params.add(Integer.valueOf(companyId));
/*      */       }
/*      */     }
/*      */ 
/* 1108 */     sql.append(" GROUP BY ResponsibleUserId");
/* 1109 */     QueryRunner runner = new QueryRunner();
/*      */     try {
/* 1111 */       return (List)runner.query(conn, sql.toString(), new MyMapListHandler(), 
/* 1112 */         params.toArray());
/*      */     } catch (SQLException e) {
/* 1114 */       logger.warn("getDealsTotalNumInfo failed", e);
/* 1115 */       throw new DBException();
/*      */     } finally {
/*      */       try {
/* 1118 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/* 1120 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*      */   }
/*      */ 
/*      */   public List<Map<String, Object>> getWonDealsInfo(int companyId, String groupIds, Date startDate, Date endDate)
/*      */   {
/* 1136 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 1137 */     if (conn == null) {
/* 1138 */       return null;
/*      */     }
/* 1140 */     StringBuffer sql = new StringBuffer(
/* 1141 */       "SELECT count(*) AS totalNum, SUM(Price) AS totalPrice, ResponsibleUserId FROM T_Deal_Info WHERE CompanyId = ? AND DealStatus = ? ");
/* 1142 */     List params = new ArrayList();
/* 1143 */     params.add(Integer.valueOf(companyId));
/* 1144 */     params.add("2");
/*      */ 
/* 1146 */     if ((groupIds != null) && (groupIds.trim().length() > 0)) {
/* 1147 */       if (!groupIds.contains(",")) {
/* 1148 */         sql.append(" AND ResponsibleUserId IN (SELECT UserId FROM T_User_Info WHERE CompanyId = ? AND GroupId = ?)");
/* 1149 */         params.add(Integer.valueOf(companyId));
/* 1150 */         params.add(Integer.valueOf(Util.str2Int(groupIds)));
/*      */       } else {
/* 1152 */         sql.append(" AND ResponsibleUserId IN (SELECT UserId FROM T_User_Info WHERE CompanyId = ? AND GroupId IN (" + 
/* 1153 */           groupIds + "))");
/* 1154 */         params.add(Integer.valueOf(companyId));
/*      */       }
/*      */     }
/*      */ 
/* 1158 */     if (startDate != null) {
/* 1159 */       sql.append(" AND DATEDIFF(DealStatusChangeDate, ?) >= 0 ");
/* 1160 */       params.add(startDate);
/*      */     }
/* 1162 */     if (endDate != null) {
/* 1163 */       sql.append(" AND DATEDIFF(DealStatusChangeDate, ?) <= 0 ");
/* 1164 */       params.add(endDate);
/*      */     }
/*      */ 
/* 1167 */     sql.append(" GROUP BY ResponsibleUserId");
/* 1168 */     QueryRunner runner = new QueryRunner();
/*      */     try {
/* 1170 */       return (List)runner.query(conn, sql.toString(), new MyMapListHandler(), 
/* 1171 */         params.toArray());
/*      */     } catch (SQLException e) {
/* 1173 */       logger.warn("get count failed", e);
/*      */     } finally {
/*      */       try {
/* 1176 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/* 1178 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/* 1181 */     return null;
/*      */   }
/*      */ 
/*      */   public List<Map<String, Object>> getDealAllExtInfo(String dealIds)
/*      */     throws DBException, SQLException
/*      */   {
/* 1194 */     if ((dealIds == null) || (dealIds.trim().length() == 0)) {
/* 1195 */       return null;
/*      */     }
/* 1197 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 1198 */     if (conn == null) {
/* 1199 */       throw new DBException();
/*      */     }
/*      */ 
/* 1202 */     QueryRunner runner = new QueryRunner();
/*      */     try {
/* 1204 */       StringBuffer sql = new StringBuffer("SELECT Type, Info1, DealId FROM T_Deal_Ext_Info WHERE DealId IN (");
/* 1205 */       sql.append(dealIds).append(") ORDER BY DealId , Type DESC");
/* 1206 */       return (List)runner.query(conn, sql.toString(), new MyMapListHandler());
/*      */     } finally {
/*      */       try {
/* 1209 */         DbUtils.close(conn);
/*      */       } catch (SQLException e) {
/* 1211 */         logger.warn("close conn failed", e);
/*      */       }
/*      */     }
/*      */   }
/*      */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.db.DealManager
 * JD-Core Version:    0.6.1
 */